package com.example.demo.test;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2023-02-10
 * Time:17:32
 */
@RestController
@RequestMapping("/user")
public class userController {
    @RequestMapping("/login2")
    public boolean login(HttpServletRequest request,String username,String password){
        //if(name!=null&&name!=""&&password!=null&&password!="")
        //非空判断等同于上面
        if (StringUtils.hasLength(username)&&StringUtils.hasLength(password)){
            //判断账号密码：假设为zhangsan，
            if("zhangsan".equals(username)&&"zhangsan".equals(password)){
                //创建会话session
                HttpSession session=request.getSession();
                session.setAttribute("userinfo","zhangsan");
                return true;
            }else {
                return false;
            }
        }
        return false;
    }
    @RequestMapping("/del")
    public String del(){
        return "测试";
    }

    @RequestMapping("/del2")
    public String del2(){
        return "测试";
    }
}
